package com.bizmerce.rnd.oms.codemng.service.impl;

import java.util.HashMap;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Repository;

import com.bizmerce.rnd.oms.codemng.service.DeMinimisParamVO;
import com.bizmerce.rnd.oms.codemng.service.DeMinimisVO;
import com.bizmerce.rnd.oms.codemng.web.CodeMngController;

import egovframework.rte.psl.dataaccess.EgovAbstractDAO;

@SuppressWarnings("unchecked")
@Repository("deminimisDAO")
public class DeMinimisDAO extends EgovAbstractDAO {
	/**
	 * 미소기준 - 정보 가져오기
	 */
	public List<DeMinimisVO> selectDeMin(String id)  {
		HashMap<String, String> param = new HashMap<String, String>();
		param.put("AGREE_CD", id);
		List<DeMinimisVO> deminimis = getSqlMapClientTemplate().queryForList("CodeMng.selectDeMin", param);
		return deminimis;
	}

	/**
	 * 미소기준 -저장
	 */
	Log log = LogFactory.getLog(CodeMngController.class);
	public void updateDemin(String id, DeMinimisParamVO dem)  {
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put("AGREE_CD", id);
		String division = dem.getDivision();
		String[] divi = division.split(",");

		if(divi[0].equals("일반품목")){
			param.put("DIVI", "일반품목");
			param.put("APPL_YN", dem.isGeneralApply());
			param.put("MIN_RULE_PRMS_RATE", dem.getGeneralRate());
			getSqlMapClientTemplate().update("CodeMng.updateDemin", param);
		}
		if(divi[1].equals("농수산물")){
			param.put("DIVI", "농수산물");
			param.put("APPL_YN", dem.isAgricultureApply());
			param.put("MIN_RULE_PRMS_RATE", dem.getAgricultureRate());
			getSqlMapClientTemplate().update("CodeMng.updateDemin", param);
		}
		if(divi[2].equals("섬유류")){
			param.put("DIVI", "섬유류");
			param.put("APPL_YN", dem.isTextilesApply());
			param.put("MIN_RULE_PRMS_RATE", dem.getTextilesRate());
			getSqlMapClientTemplate().update("CodeMng.updateDemin", param);
		}
	}
}